# 一副扑克牌52张（除了大小王），4个玩家在玩，模拟系统发牌、洗牌和整理牌，具体需求如下：
# 【1】先按照顺序打印出一副扑克牌
# 【2】在没有洗牌的情况下，输出发到四个玩家的扑克牌
# 【3】实现对扑克牌的洗牌，然后输出发到四个玩家的扑克牌
# 【4】对于洗牌后的四个玩家的扑克牌进行整理整理规则1：数字从小到大
# 从小到大（3、4、5、6、7、8、9、10、J、Q、K、A、2）整理规则2：在数字相同的情况下，按照花色（黑、红、梅、方）的顺序

import random


class Poker():
    def __init__(self):
        self.card_pool = []
        self.card_number = ("A", "2", "3", "4", "5", "6", "7", "8", "9", "10",
                            "J", "Q", "K")
        self.card_suit = ("黑", "红", "梅", "方")
        self.player_cards = [[], [], [], []]

    def generate_card(self):
        # 生成牌
        try:
            for each in self.card_suit:
                for i in self.card_number:
                    temp = each + i
                    self.card_pool.append(temp)
        except:
            pass

    def deal_card(self):
        # 发牌
        while len(self.card_pool) > 0:
            for i in range(4):
                card = self.card_pool.pop(0)
                self.player_cards[i].append(card)

    def shuffle_card(self):
        # 洗牌
        random.shuffle(self.card_pool)

    def sort_card(self):
        # 定义排序规则
        rule_num_dic = {
            "3": 0,
            "4": 1,
            "5": 2,
            "6": 3,
            "7": 4,
            "8": 5,
            "9": 6,
            "10": 7,
            "J": 8,
            "Q": 9,
            "K": 10,
            "A": 11,
            "2": 12
        }
        rule_suit_dic = {"黑": 0, "红": 1, "梅": 2, "方": 3}

        # 排序方法
        def rule_num(elem):
            x = elem[1:]
            return rule_num_dic[x]

        def rule_suit(elem):
            x = elem[0]
            return rule_suit_dic[x]

        for i in range(4):
            self.player_cards[i].sort(
                key=lambda x: (rule_num(x), rule_suit(x)))

    def playing(self):
        # print("==============生成牌===================")
        self.generate_card()
        # print(self.card_pool)

        # print("================洗牌=================")
        self.shuffle_card()
        # print(self.card_pool)

        # print("================发牌=================")
        self.deal_card()
        # print(self.player_cards)

        # print("=================排序================")
        self.sort_card()
        # print(self.player_cards)

        for i in range(1, 5):
            print("玩家{}的牌：{}".format(i, self.player_cards[i - 1]))


if __name__ == "__main__":
    this_project = Poker()
    this_project.playing()